import { http } from '../../http'
import { ActivityTeam, GetTeamStatus, GetTeamsVo, TeamVo, WorkingTeamVo } from '@/service/api/modules/groupon/response'
import { PaymentResult, ResponsePage } from '@/service/api/type'
import { GetGrouponListOfCouponParam, GetMyGrouponListParam } from '@/service/api/modules/groupon/param'

// 获取拼团详情
const getGrouponDetail = (groupId: number | string) => http.get<number | string, TeamVo>(`/activity/team/${groupId}`)

// 创建拼团
const createGroupon = (couponId: number | string) => http.post<number | string, ActivityTeam>(`/activity/coupon/${couponId}/team`)

// 获取指定优惠券的已有拼团列表
const getGrouponListOfCoupon = (params: GetGrouponListOfCouponParam) => http.get<GetGrouponListOfCouponParam, ResponsePage<WorkingTeamVo>>(`/activity/coupon/${params.couponId}/team`, params)

// 获取我的拼团列表
const getMyGrouponList = (params: GetMyGrouponListParam) => http.get<GetMyGrouponListParam, ResponsePage<GetTeamsVo>>('/activity/teams', params)

// 支付加入拼团
const payToJoinGroupon = (groupId: number | string) => http.post<number | string, PaymentResult>(`/activity/coupon/team/${groupId}/pay/order`)

// 取消拼团
const cancelGroupon = (groupId: number | string) => http.put<number | string, void>(`/activity/team/${groupId}/cancel`)

// 获取拼团状态
const getGrouponStatus = (groupId: number | string) => http.get<string, GetTeamStatus>(`/activity/coupon/team/${groupId}/status`)

export default {
  getGrouponDetail,
  createGroupon,
  getGrouponListOfCoupon,
  getMyGrouponList,
  payToJoinGroupon,
  cancelGroupon,
  getGrouponStatus
}
